import axios from 'axios';
let extend_axios={
    init(){
        this.handleHttpHeader($root);
    },
    handleHttpHeader($root){
        $root.$http = axios;
        let token = this.getCookie('token');         
        if(!token){
            axios.defaults.headers['token']="";
            return;
        }            
        axios.defaults.headers['token'] = token;
        
    },
    getCookie(cookie_name) {
        var allcookies = document.cookie;
        var cookie_pos = allcookies.indexOf(cookie_name);
        if (cookie_pos != -1) {
            cookie_pos = cookie_pos + cookie_name.length + 1; 
            var cookie_end = allcookies.indexOf(";", cookie_pos);
            if (cookie_end == -1) {
                cookie_end = allcookies.length;
            }
            var value = unescape(allcookies.substring(cookie_pos, cookie_end)); 
        }
        return value;
    }
};
extend_axios.init();
